var Timer = 
{
	Items : {}, 
};
Timer.Add = (function(name, callback, interval, repeat, trigger_at_once)
{
	if(repeat !== false)
		repeat = true;
	Timer.Items[name] = {
		Name: name, 
		Callback: callback, 
		Interval: interval, 
		Repeat: repeat
	};
	if(chrome.alarms)
	{
		chrome.alarms.create(name, 
			{delayInMinutes: interval, repeating: repeat});
	}
	else
	{
		if(repeat)
			Timer.Items[name]._id = window.setInterval(callback, 
				interval * 60 * 1000);
		else
			Timer.Items[name]._id = window.setTimeout(callback, 
				interval * 60 * 1000);
	}
	if(trigger_at_once && repeat)
		callback();
});

chrome.alarms && chrome.alarms.onAlarm.addListener(function(alarm)
{
	var item;
	if(item = Timer.Items[alarm.name])
		item.callback();
});

